import request from '@/utils/request'

export function sendCode(phone) {
  return request({
    url: '/users/verification/code',
    method: 'get',
    params: { phone }
  })
}

export function createUser(user) {
  return request({
    url: '/users',
    method: 'post',
    data: user
  })
}

export function getUserRoles(userId) {
  const url = userId ? '/users/' + userId + '/roles' : '/roles'
  return request({
    url,
    method: 'get'
  })
}

export function getUserInfo(userId) {
  return request({
    url: '/users/' + userId,
    method: 'get'
  })
}

export function resetPassword({ phone, password, code }) {
  return request({
    url: '/users/retrieval',
    method: 'patch',
    data: { phone, password, code }
  })
}
